﻿using System;

using Microsoft.Xna.Framework;

namespace Ah.Testudin.Engine.Processes
{
    public class DelayProcess : ProcessBase
    {
        #region Private Member Variables

        private long _timeToDelay;

        private long _timeDelayedSoFar;

        #endregion

        #region Constructors

        public DelayProcess(long timeToDelay)
            : this(timeToDelay, null)
        {
        }

        public DelayProcess(
            long timeToDelay,
            IProcess childProcess)
            : base(childProcess)
        {
            if (timeToDelay <= 0)
            {
                throw new ArgumentOutOfRangeException("timeToDelay");
            }

            _timeToDelay = timeToDelay;

            _timeDelayedSoFar = 0;
        }

        #endregion

        #region ProcessBase

        public override void Update(GameTime gameTime)
        {
            _timeDelayedSoFar += gameTime.ElapsedGameTime.Milliseconds;

            if (_timeDelayedSoFar >= _timeToDelay)
            {
                _state = ProcessState.Succeeded;
            }
        }

        #endregion
    }
}
